// 用户数据模块
import {
  SUDOKUERRORNUM,
  GAME_LIST,
  ISRELOAD,
  ISONECEMOSTPASS24,
  LEASTTIME24,
  ONECEMOSTPASSCOUNT
} from '../types.js'
const state = {
  isReload: uni.getStorageSync('isReload') ? uni.getStorageSync('isReload') : false,
  isOneceMostPass24: uni.getStorageSync('isOneceMostPass24')
    ? uni.getStorageSync('isOneceMostPass24')
    : true,
  leastTime24: uni.getStorageSync('leastTime24') ? uni.getStorageSync('leastTime24') : 0,
  oneceMostPassCount: uni.getStorageSync('oneceMostPassCount')
    ? uni.getStorageSync('oneceMostPassCount')
    : 0,
  sudokuErrorNum: uni.getStorageSync('sudokuErrorNum') ? uni.getStorageSync('sudokuErrorNum') : 5,
  gameList: uni.getStorageSync('gameList')
    ? uni.getStorageSync('gameList')
    : [
        {
          name: '容易',
          type: 0,
          levelList: []
        },
        {
          name: '中等',
          type: 1,
          levelList: []
        },
        {
          name: '困难',
          type: 2,
          levelList: []
        },
        {
          name: '专家',
          type: 3,
          levelList: []
        }
      ]
}

const actions = {
  setSudokuErrorNum({ commit }, data = {}) {
    commit('SUDOKUERRORNUM', data)
  },

  setGameList({ commit }, data = {}) {
    commit('GAME_LIST', data)
  },

  setIsReload({ commit }, data = {}) {
    commit('ISRELOAD', data)
  },

  setIsOneceMostPass24({ commit }, data = {}) {
    commit('ISONECEMOSTPASS24', data)
  },

  setLeastTime24({ commit }, data = {}) {
    commit('LEASTTIME24', data)
  },

  setOneceMostPassCount({ commit }, data = {}) {
    commit('ONECEMOSTPASSCOUNT', data)
  }
}

const mutations = {
  [SUDOKUERRORNUM](state, data) {
    uni.setStorageSync('sudokuErrorNum', data)
    state.sudokuErrorNum = data
  },
  [GAME_LIST](state, data) {
    uni.setStorageSync('gameList', data)
    state.gameList = data
  },
  [ISRELOAD](state, data) {
    uni.setStorageSync('isReload', data)
    state.isReload = data
  },
  [ISONECEMOSTPASS24](state, data) {
    uni.setStorageSync('isOneceMostPass24', data)
    state.isOneceMostPass24 = data
  },
  [LEASTTIME24](state, data) {
    uni.setStorageSync('leastTime24', data)
    state.leastTime24 = data
  },
  [ONECEMOSTPASSCOUNT](state, data) {
    uni.setStorageSync('oneceMostPassCount', data)
    state.oneceMostPassCount = data
  }
}

const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}
